package com.eims.sls_app.ui;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.android.volley.toolbox.MySingleton;
import com.android.volley.toolbox.RequestParams;
import com.contans.view.CirclePersonInfoVo;
import com.eims.sls_app.dataaccess.CircleBean;
import com.eims.sls_app.dataaccess.CircleBean.CommentBean;
import com.eims.sls_app.dataaccess.CircleBean.SchemeinfoBean;
import com.eims.sls_app.dataaccess.CircleBean.SchemeinfoBean.InformationIdBean;
import com.eims.sls_app.dataaccess.CircleBean.TopicBean;
import com.eims.sls_app.dataaccess.LotteryContent;
import com.eims.sls_app.dataaccess.Schemes;
import com.eims.sls_app.dataaccess.utils.HttpUtils;
import com.eims.sls_app.protocol.RspBodyBaseBean;
import com.eims.sls_app.ui.adapter.CirclePersoninfoAdapter;
import com.eims.sls_app.utils.App;
import com.eims.sls_app.utils.AppTools;
import com.eims.sls_app.utils.App;
import com.eims.sls_app.utils.ImageManager;
import com.eims.sls_app.utils.LotteryUtils;
import com.eims.sls_app.view.MyToast;
import com.eims.sls_app.view.XCRoundImageView;
import com.google.gson.Gson;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import bls.juejin.cn.R;
import progressBar.ProgressDialogBar;

public class CirclePersonInfo extends MyBaseActivity implements OnClickListener {
	private String TAG = "CirclePersonInfo";
	private PullToRefreshListView circle_item_listView;
	private TextView circle_item_hint;
	public String opt, auth, personinfo, infoGuanzhu, info, time, imei, crc; // 格式化后的参数
	private boolean isToFirst = true;
	private ArrayList<String> list = new ArrayList<String>();
	private CirclePersoninfoAdapter adapter;
	private MyHandler mHandler;
	private MyAsynTask mMyAsynTask;
	private MySingleton mySingleton;
	private CircleBean circleBean, circleBean1;
	private InformationIdBean informationIdBean;
	private GetInfoMyHandler myinfoHandler;
	private String schemeid, userId = "";

	private CirclePersonInfoVo circlePersonInfo;
	private ImageButton ibBack;
	private XCRoundImageView ivHead;
	private TextView tvName, tvGuanzhu, tvFensi, tvTouzhongNUm, tvWholeJangjin, tvFangan, tvZHongjiangNum, tvJiangjin,
			tvAddguanzhu;
	private GuanzhuAsynTask guanzhuAsynTask;
	private guanHuMyHandler gzmHandler;
	private int selectLoctonParse;
	private int fanganBUm = 0;

	private String getopt = "46"; // 格式化后的 opt
	private String getauth, getinfo, gettime, getimei, getcrc, getkey; // 格式化后的参数
	private int getInfoPosition;
	Schemes scheme;
	private String JinECost; // 金额消费
	private String CaiJinCost;// 彩金消费
	private String reMainCaiJin;// 剩余彩金
	private boolean isJoin = true;
	List<InformationIdBean> informationIdBeans;
	public getMyHandler getMyHandler;
	private ProgressDialog pd;
	public boolean isFirst = true;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.circle_person_info);
		try {
			ProgressDialogBar.stopProgress();
		} catch (Exception e) {
			// TODO: handle exception
		}
		App.activityS.add(this);
		App.activityS1.add(this);
		Intent intent = getIntent();

		Bundle bundle = intent.getExtras();
		userId = bundle.getString("userId");
//		userId = "";
		// schemeid= bundle.getString("schemeid");
		Log.e(TAG, userId);
		mHandler = new MyHandler();
		getMyHandler = new getMyHandler();

		myinfoHandler = new GetInfoMyHandler();
		myinfoHandler.sendEmptyMessage(23);
		gzmHandler = new guanHuMyHandler();
		init();
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		try {
			ProgressDialogBar.stopProgress();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.btn_back:
			finish();
			break;
		case R.id.tv_add_guanzhu:

			infoGuanzhu = circleBean.topic.get(0).userid + "";
			guanzhuAsynTask = new GuanzhuAsynTask();
			guanzhuAsynTask.execute();
			break;
		default:
			break;
		}
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	private void init() {

		mySingleton = MySingleton.getInstance(this);
		circle_item_listView = (PullToRefreshListView) findViewById(R.id.circle_item_listView);
		circle_item_hint = (TextView) findViewById(R.id.circle_item_hint);

		ibBack = (ImageButton) findViewById(R.id.btn_back);
		ivHead = (XCRoundImageView) findViewById(R.id.iv_item_head);
		tvName = (TextView) findViewById(R.id.nameTv);
		ibBack.setOnClickListener(this);
		tvGuanzhu = (TextView) findViewById(R.id.tv_guanzhu);
		tvFensi = (TextView) findViewById(R.id.tv_fensi);
		tvTouzhongNUm = (TextView) findViewById(R.id.tv_touzhong_num);
		tvWholeJangjin = (TextView) findViewById(R.id.whole_total_num);
		tvFangan = (TextView) findViewById(R.id.tv_fanan_num);
		tvZHongjiangNum = (TextView) findViewById(R.id.tv_zhongjiang_num);
		tvJiangjin = (TextView) findViewById(R.id.tv_jiangjin);

		tvAddguanzhu = (TextView) findViewById(R.id.tv_add_guanzhu);
		tvAddguanzhu.setOnClickListener(this);
		personinfo = userId;
		// info = App.getDaString();
		try {
			ProgressDialogBar.startProgress(CirclePersonInfo.this, "ss", false);
		}catch (Exception e){

		}

		MyAsynTask myAsynTask = new MyAsynTask();
		myAsynTask.execute();

		// circle_item_listView.onRefreshComplete();
		circle_item_listView.setOnRefreshListener(new OnRefreshListener2() {

			@Override
			public void onPullDownToRefresh(PullToRefreshBase refreshView) {
				circle_item_listView.getLoadingLayoutProxy(true, false)
						.setLastUpdatedLabel("最近更新: " + LotteryUtils.Long2DateStr_detail(System.currentTimeMillis()));
				// informations.clear();
				isToFirst = true;
				isFirst = true;
				if (circleBean.topic != null) {
					circleBean.topic.clear();
					circleBean.schemeinfo.clear();
					adapter.notifyDataSetChanged();

				} else {

				}
				MyAsynTask myAsynTask = new MyAsynTask();
				myAsynTask.execute();
				circle_item_listView.postDelayed(new Runnable() {

					@Override
					public void run() {

						circle_item_listView.onRefreshComplete();
					}
				}, 1000);
			}

			@Override
			public void onPullUpToRefresh(PullToRefreshBase refreshView) {
				// TODO Auto-generated method stub
				// MyToast.getToast(getActivity(), "最后一个").show();
				isFirst = false;
				if (circleBean.topic != null) {
					if (circleBean.topic.size() < 10) {
						// MyToast.getToast(getActivity(), "这是最后一页了").show();

						adapter.notifyDataSetChanged();
						circle_item_listView.postDelayed(new Runnable() {

							@Override
							public void run() {

								circle_item_listView.onRefreshComplete();
							}
						}, 1000);
					} else {

						adapter.notifyDataSetChanged();
						mMyAsynTask = new MyAsynTask();
						mMyAsynTask.execute();
						circle_item_listView.postDelayed(new Runnable() {

							@Override
							public void run() {

								circle_item_listView.onRefreshComplete();
							}
						}, 1000);

					}
				} else {
					adapter.notifyDataSetChanged();
					circle_item_listView.postDelayed(new Runnable() {

						@Override
						public void run() {
							circle_item_hint.setVisibility(View.GONE);
							circle_item_listView.onRefreshComplete();
						}
					}, 1000);
				}

			}
		});

		// circle_item_listView.setOnItemClickListener(new OnItemClickListener() {
		//
		// @Override
		// public void onItemClick(AdapterView<?> arg0, View arg1, int position, long
		// arg3) {
		// getInfoPosition = position - 1;
		// if (TimeCompare(App.getDaString(),
		// circleBean.topic.get(getInfoPosition).getStoptime())) {
		// Toast.makeText(CirclePersonInfo.this, "当前方案未开奖，不能查看！",
		// Toast.LENGTH_SHORT).show();
		// } else {
		// pd = BaseHelper.showProgress(CirclePersonInfo.this, "", "加载中...", true,
		// false);
		//
		// GetMyAsynTask getMyAsynTask = new GetMyAsynTask();
		// getMyAsynTask.execute();
		// }
		//
		// }
		// });

	}

	private boolean TimeCompare(String date1, String date2) {
		// 格式化时间
		boolean isStop = false;
		SimpleDateFormat CurrentTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		// String date1="2015-01-25 09:12:09";
		// String date2="2015-01-29 09:12:11";

		try {

			Date beginTime = CurrentTime.parse(date1);
			Date endTime = CurrentTime.parse(date2);
			if ((endTime.getTime() - beginTime.getTime()) > 0) {
				isStop = true;
			} else {
				isStop = false;
			}
			// 判断是否大于两天

		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return isStop;

	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
	}

	class GetInfoAsynTask extends AsyncTask<Integer, Integer, String> {

		String error = "-1";

		@Override
		protected String doInBackground(Integer... params) {

			opt = "93";
			time = RspBodyBaseBean.getTime();
			imei = RspBodyBaseBean.getIMEI(CirclePersonInfo.this);
			// info = RspBodyBaseBean.change_TheSun(schemeId+"", context_Sun);
			info = RspBodyBaseBean.getCirclePersonIn(userId, AppTools.getDaString());
			// String key = MD5.md5(App.user.getUserPass() + App.MD5_key);
			String key = App.key;

			crc = RspBodyBaseBean.getCrc(time, imei, key, personinfo, App.user.getUid());
			auth = RspBodyBaseBean.getAuth(crc, time, imei, App.user.getUid());

			String[] values = { opt, auth, personinfo };
			Log.i(TAG, "晒单信息" + RequestParams.convertParams(CirclePersonInfo.this, opt, personinfo));
			String result = HttpUtils.doPost(App.names, values, App.path);

			System.out.println("晒单：" + result + "");
			if (result != null) {
				try {
					JSONArray arr = new JSONArray(result);
					String s = arr.getString(0);

					Gson gson = new Gson();
					circlePersonInfo = gson.fromJson(s, CirclePersonInfoVo.class);
					Log.e(TAG, circlePersonInfo.toString());
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					return "-500";

				}
			}

			if ("-500".equals(result)) {
				return "-500";
			}

			error = "0";
			return error;
		}

		@Override
		protected void onPostExecute(String result) {

			myinfoHandler.sendEmptyMessage(Integer.parseInt(result));

			super.onPostExecute(result);
		}
	}

	public String formateRate(String rateStr) {
		if (rateStr.indexOf(".") != -1) {
			// 获取小数点的位置
			int num = 0;
			num = rateStr.indexOf(".");

			// 获取小数点后面的数字 是否有两位 不足两位补足两位
			String dianAfter = rateStr.substring(0, num + 1);
			String afterData = rateStr.replace(dianAfter, "");
			if (afterData.length() < 2) {
				afterData = afterData + "0";
			} else {
				afterData = afterData;
			}
			return rateStr.substring(0, num) + "." + afterData.substring(0, 2);
		} else {
			if (rateStr == "1") {
				return "100";
			} else {
				return rateStr;
			}
		}
	}

	public boolean isMobileNO(String mobiles) {
		Pattern p = Pattern.compile("1[0-9]{10}");
		Matcher m = p.matcher(mobiles);
		return m.matches();
	}

	@SuppressLint("HandlerLeak")
	class GetInfoMyHandler extends Handler {
		@Override
		public void handleMessage(Message msg) {

			switch (msg.what) {
			case 23:
				Log.e(TAG, "获取信息");
				info = RspBodyBaseBean.getCirclePersonIn(userId, AppTools.getDaString());
				//
				GetInfoAsynTask getInfoAsynTask = new GetInfoAsynTask();
				getInfoAsynTask.execute();
				break;
			case 0:
				if (circlePersonInfo != null) {
					final String name = circlePersonInfo.getName();
					// String name = topicBeans.get(position).name;
					final String isname;
					if (isMobileNO(name)) {
						isname = name.substring(0, 3) + "****" + name.substring(7, name.length());
						// holder.tv_name.setText());
					} else {
						isname = name;
						// holder.tv_name.setText(name.substring(0, 2)+"**");
					}
					ImageManager.getInstance().displayImage(App.url + circlePersonInfo.getHeadUrl(), ivHead,
							ImageManager.getViewsHeadOptions());
					tvName.setText(isname);
					tvGuanzhu.setText("关注  " + circlePersonInfo.getInterest());
					tvFensi.setText("粉丝  " + circlePersonInfo.getInterested());
					tvTouzhongNUm.setText(
							"近15天累计" + circlePersonInfo.getTotalcount() + "投" + circlePersonInfo.getWincount() + "中");
					tvWholeJangjin.setText("奖金" + formateRate(circlePersonInfo.getTotalwinmoney()));
					tvFangan.setText(circlePersonInfo.getTotal());
					tvZHongjiangNum.setText(circlePersonInfo.getWin());
					tvJiangjin.setText(formateRate(circlePersonInfo.getTotalwin()));
				}

				break;
			case 1:

				break;
			case -1:

				break;
			case -500:
				Toast.makeText(CirclePersonInfo.this, "网络异常，请重新打开网络", Toast.LENGTH_SHORT).show();
				break;
			default:
				break;
			}
			super.handleMessage(msg);
		}

	}

	class MyAsynTask extends AsyncTask<Integer, Integer, String> {

		String error = "-1";

		@Override
		protected String doInBackground(Integer... params) {
			
			opt = "94";// 92
			time = RspBodyBaseBean.getTime();
			imei = RspBodyBaseBean.getIMEI(CirclePersonInfo.this);

			if (isFirst) {
				info = RspBodyBaseBean.getCirclePersonIn(userId, AppTools.getDaString());
			} else {
				if (circleBean.topic != null) {
					if (circleBean.topic.size() < 10) {
						// MyToast.getToast(getActivity(), "这是最后一页了").show();

					} else {

						info = RspBodyBaseBean.getCirclePersonIn(userId, circleBean.topic.get(9).datetime);
					}

				}
			}
			// String key = MD5.md5(App.user.getUserPass() + App.MD5_key);
			String key = App.key;
			if (App.user == null) {
				crc = RspBodyBaseBean.getCrc(time, imei, key, info, "-1");
				auth = RspBodyBaseBean.getAuth(crc, time, imei, "-1");
			} else {
				crc = RspBodyBaseBean.getCrc(time, imei, key, info, App.user.getUid());
				auth = RspBodyBaseBean.getAuth(crc, time, imei, App.user.getUid());
			}

			String[] values = { opt, auth, info };
			Log.i(TAG, "晒单" + RequestParams.convertParams(CirclePersonInfo.this, opt, info));
			String result = HttpUtils.doPost(App.names, values, App.path);
			Log.e(TAG, "晒单11" + result);
			System.out.println("晒单：" + result);
			if ("-500".equals(result)) {
				Log.e(TAG, "晒单11" + "jixu1");
				return "-500";

			}
			Log.e(TAG, "晒单11" + "jixu2");
			circleBean = new CircleBean();
			try {
				JSONObject jsonObject = new JSONObject(result);
				JSONArray topic = jsonObject.getJSONArray("topic");
				List<TopicBean> topicBeans = new ArrayList<CircleBean.TopicBean>();

				Log.e(TAG, "晒单11" + topic.toString());
				if (topic.equals("[]")) {
					Log.e(TAG, "晒单11" + "jixu3");
					error = "1";
				}
				Log.e(TAG, "晒单11长度" + topic.length());

				int topSize = topic.length();

				for (int i = 0; i < topSize; i++) {
					Log.e(TAG, "晒单11" + i);
					JSONObject obj = topic.getJSONObject(i);
					TopicBean topicBean = new TopicBean();
					topicBean.id = obj.optInt("id");
					topicBean.userid = obj.optInt("userid");
					topicBean.detail = obj.optString("detail");
					topicBean.schemeid = obj.optInt("schemeid");
					topicBean.up = obj.optString("up");
					topicBean.datetime = obj.optString("datetime");
					// topicBean.enable = obj.optBoolean("enable");
					topicBean.yjjj = obj.optString("yjjj");
					topicBean.stoptime = obj.getString("stoptime");
					topicBean.PlayTypeID = obj.optString("PlayTypeID");
					topicBean.follCount = obj.optString("follCount");

					String canCopy = obj.getString("cancopy");
					if (canCopy.equals("0")) {
						topicBean.cancopy = false;
					} else {
						topicBean.cancopy = true;
					}

					topicBean.name = obj.optString("name");
					topicBean.HeadUrl = obj.optString("HeadUrl");
					topicBean.Wins = obj.optString("Wins");
					topicBean.iswin = obj.optString("iswin");
					topicBean.interest = obj.optString("interest");
					topicBean.isopen = obj.optString("isopen");
					topicBean.hb = obj.optString("hb");
					topicBeans.add(topicBean);
				}

				JSONArray comment = jsonObject.getJSONArray("comment");
				List<List<CommentBean>> commentBeans = new ArrayList<List<CommentBean>>();
				for (int i = 0; i < comment.length(); i++) {
					Log.e(TAG, "晒单21," +i);
					JSONArray jsonArray = comment.getJSONArray(i);
					List<CommentBean> commentBeanlists = new ArrayList<CircleBean.CommentBean>();
					for (int j = 0; j < jsonArray.length(); j++) {
						Log.e(TAG, "晒单22," +j);
						JSONObject object2 = jsonArray.getJSONObject(j);
						CommentBean commentBean = new CommentBean();
						commentBean.id = object2.optInt("id");
						commentBean.cid = object2.optInt("cid");
						commentBean.uid = object2.optInt("uid");
						commentBean.detail = object2.optString("detail");
						commentBean.time = object2.optString("time");
						commentBean.name = object2.optString("name");
						commentBean.datetime = object2.optString("datetime");
						commentBeanlists.add(commentBean);
					}
					commentBeans.add(commentBeanlists);
				}

				JSONArray schemeinfo = jsonObject.getJSONArray("schemeinfo");
				List<SchemeinfoBean> schemeinfoBeans = new ArrayList<CircleBean.SchemeinfoBean>();
				for (int i = 0; i < schemeinfo.length(); i++) {
					Log.e(TAG, "晒单31," +i);
					JSONObject object = schemeinfo.getJSONObject(i);
					SchemeinfoBean schemeinfoBean = new SchemeinfoBean();
					schemeinfoBean.buymoney = object.optString("buymoney");
					schemeinfoBean.buyTime = object.optString("buyTime");
					schemeinfoBean.preBetType = object.optString("preBetType");
					schemeinfoBean.isHide = object.optInt("isHide");
					schemeinfoBean.stopsellingtime = object.optString("stopsellingtime");
					schemeinfoBean.secretMsg = object.optString("secretMsg");
					schemeinfoBean.passTypeInfo = object.optString("passTypeInfo");
					// JSONArray optimization = object.getJSONArray("optimization");
					JSONArray InformationId = object.getJSONArray("informationId");
					List<InformationIdBean> informationIdBeans = new ArrayList<CircleBean.SchemeinfoBean.InformationIdBean>();
					for (int j = 0; j < InformationId.length(); j++) {
						Log.e(TAG, "晒单32," +j);
						JSONObject jsonObject2 = InformationId.getJSONObject(j);
						informationIdBean = new InformationIdBean();
						informationIdBean.ID = jsonObject2.optString("ID");
						informationIdBean.SchemeID = jsonObject2.optString("SchemeID");
						informationIdBean.PlayType = jsonObject2.optString("PlayType");
						informationIdBean.MatchNumber = jsonObject2.optString("MatchNumber");
						informationIdBean.Game = jsonObject2.optString("Game");
						informationIdBean.MaiTeam = jsonObject2.optString("MaiTeam");
						informationIdBean.GuestTeam = jsonObject2.optString("GuestTeam");
						informationIdBean.StopSelling = jsonObject2.optString("StopSelling");
						informationIdBean.LetBile = jsonObject2.optString("LetBile");
						informationIdBean.Score = jsonObject2.optString("Score");
						informationIdBean.Results = jsonObject2.optString("Results");
						informationIdBean.PassType = jsonObject2.optString("PassType");
						informationIdBean.issue = jsonObject2.optString("issue");
						informationIdBean.Status = jsonObject2.optString("Status");
						informationIdBean.EndTime = jsonObject2.optString("EndTime");
						informationIdBean.investContent = jsonObject2.optString("investContent");
						informationIdBean.Content = jsonObject2.optString("Content");
						informationIdBean.MainLoseball = jsonObject2.optString("MainLoseball");
						informationIdBean.LetScore = jsonObject2.optString("LetScore");
						informationIdBean.BigSmallScore = jsonObject2.optString("BigSmallScore");
						informationIdBean.strresult = jsonObject2.optString("strresult");
						informationIdBeans.add(informationIdBean);

					}
					schemeinfoBean.informationId = informationIdBeans;
					schemeinfoBeans.add(schemeinfoBean);
				}
				circleBean.comment = commentBeans;

				circleBean.topic = topicBeans;
				circleBean.schemeinfo = schemeinfoBeans;
				error = "0";
			} catch (Exception e) {
				error = "-1";
				Log.e(TAG, "e晒单11" + e.getMessage());
				e.printStackTrace();
			}

			return error;
		}

		@Override
		protected void onPostExecute(String result) {
			circle_item_hint.setVisibility(View.GONE);
			circle_item_listView.setMode(Mode.BOTH);
			mHandler.sendEmptyMessage(Integer.parseInt(result));
			circle_item_listView.onRefreshComplete();
			super.onPostExecute(result);
		}
	}

	@SuppressLint("HandlerLeak")
	class MyHandler extends Handler {
		@Override
		public void handleMessage(Message msg) {
			try {
				ProgressDialogBar.stopProgress();
			} catch (Exception e) {
				// TODO: handle exception
			}
			switch (msg.what) {
			case 0:
				if (isToFirst) {
					Log.e(TAG, "晒单11" + "233");
					adapter = new CirclePersoninfoAdapter(CirclePersonInfo.this, circleBean.topic,
							circleBean.schemeinfo, circleBean.comment);
					circle_item_listView.setAdapter(adapter);

				} else {
					Log.e(TAG, "晒单11" + "113");
					adapter.addDate(circleBean.topic, circleBean.schemeinfo, circleBean.comment);
				}
				Log.e(TAG, "晒单11" + "113" + circleBean.toString());
				// circleAdapter.setDate(circleBean.topic,
				// circleBean.schemeinfo,circleBean.comment);
				isToFirst = false;
				adapter.notifyDataSetChanged();
				if (circleBean.topic != null) {
					if (circleBean.topic.size() == 0) {
						circle_item_hint.setVisibility(View.VISIBLE);
						circle_item_hint.setText("没有更多数据");
						circle_item_listView.setMode(Mode.PULL_FROM_START);
					}
					if (circleBean.topic.size() > 0) {
						String stopGuanzhu = circleBean.topic.get(0).interest;
						if (stopGuanzhu.equals("1")) {
							tvAddguanzhu.setText("+关注");
							tvAddguanzhu.setTextColor(getResources().getColor(R.color.black));
						} else {
							tvAddguanzhu.setTextColor(getResources().getColor(R.color.gray));
							tvAddguanzhu.setText("已关注");
						}
					}
				}

				// MyToast.getToast(context, "晒单成功").show();

				break;
			case 1:
				circle_item_hint.setVisibility(View.VISIBLE);
				circle_item_hint.setText("没有数据");
				// MyToast.getToast(context, "重复晒单").show();
				break;
			case -1:
				circle_item_hint.setVisibility(View.VISIBLE);
				circle_item_hint.setText("没有数据");
				break;
			case -500:
				circle_item_hint.setVisibility(View.VISIBLE);
				circle_item_hint.setText("网络异常，请重新打开网络");

				break;
			default:
				break;
			}
			super.handleMessage(msg);
		}

	}

	// 关注
	class GuanzhuAsynTask extends AsyncTask<Integer, Integer, String> {

		String error = "-11";

		@Override
		protected String doInBackground(Integer... params) {

			opt = "90";
			time = RspBodyBaseBean.getTime();
			imei = RspBodyBaseBean.getIMEI(CirclePersonInfo.this);

			// info = RspBodyBaseBean.change_TheSun(schemeId+"", context_Sun);

			// String key = MD5.md5(App.user.getUserPass() + App.MD5_key);
			String key = App.key;
			crc = RspBodyBaseBean.getCrc(time, imei, key, infoGuanzhu, App.user.getUid());
			auth = RspBodyBaseBean.getAuth(crc, time, imei, App.user.getUid());
			String[] values = { opt, auth, infoGuanzhu };
			Log.i(TAG, "晒单" + RequestParams.convertParams(CirclePersonInfo.this, opt, infoGuanzhu));
			String result = HttpUtils.doPost(App.names, values, App.path);

			System.out.println("晒单：" + result);
			ganzhu = result;
			//
			// if (result.equals("success")) {
			// error = "10";
			// }

			return error;
		}

		@Override
		protected void onPostExecute(String result) {

			gzmHandler.sendEmptyMessage(Integer.parseInt(result));

			super.onPostExecute(result);
		}
	}

	// 点赞
	public String ganzhu;

	@SuppressLint("HandlerLeak")
	class guanHuMyHandler extends Handler {
		@Override
		public void handleMessage(Message msg) {

			switch (msg.what) {
			case 0:

				break;
			case 1:
				// MyToast.getToast(context, "重复晒单").show();
				break;
			case -2:

				break;
			case -1:

				break;
			case -11:
				Toast.makeText(CirclePersonInfo.this, ganzhu, Toast.LENGTH_SHORT).show();
				if (ganzhu.equals("关注成功")) {
					tvAddguanzhu.setTextColor(getResources().getColor(R.color.gray));
					tvAddguanzhu.setText("已关注");
				} else if (ganzhu.equals("取消关注")) {
					tvAddguanzhu.setText("+关注");
					tvAddguanzhu.setTextColor(getResources().getColor(R.color.black));
				}

				break;
			case 10:

				break;
			default:
				break;
			}
			super.handleMessage(msg);
		}

	}

	private String id;

	/*** 异步任务 用来后台获取数据 */
	class GetMyAsynTask extends AsyncTask<Void, Integer, String> {
		/**
		 * 在后台执行的程序
		 */
		@Override
		protected String doInBackground(Void... params) {
			getinfo = "{\"id\":" + adapter.getTopicBeans().get(getInfoPosition).getSchemeid() + "}";

			getopt = "15";
			Log.i("x", "投注接口 opt :" + getopt);
			Log.i("x", "投注方案详情  info  " + getinfo);

			// 加入验证后有问题,没有传key值
			getkey = App.key;
			getimei = RspBodyBaseBean.getTime();
			getimei = RspBodyBaseBean.getIMEI(CirclePersonInfo.this);
			;
			// Log.i("x", "投注方案详情 key " + key);
			id = adapter.getTopicBeans().get(getInfoPosition).getUserid() + "";
			getcrc = RspBodyBaseBean.getCrc(gettime, getimei, getkey, getinfo,
					adapter.getTopicBeans().get(getInfoPosition).getUserid() + "");
			// Log.i("x", "投注方案详情 crc " + crc);
			getauth = RspBodyBaseBean.getAuth(getcrc, gettime, getimei,
					adapter.getTopicBeans().get(getInfoPosition).getUserid() + "");
			// Log.i("x", "投注方案详情=== auth " + auth);
			String[] values = { getopt, getauth, getinfo };
			String result = HttpUtils.doPost(App.names, values, App.path);
			Log.i(TAG, "晒单" + RequestParams.convertParamsfor(CirclePersonInfo.this, getopt, getinfo, id));
			Log.i("x", "得到投注内容   " + result);
			scheme = new Schemes();
			if ("-500".equals(result))
				return result;

			if (null == result)
				return "1";
			//
			try {

				JSONObject item = new JSONObject(result);

				if ("0".equals(item.optString("error"))) {
					String schemeList = item.optString("schemeList");

					JSONArray array = new JSONArray(schemeList);

					JSONArray jsonArray2 = new JSONArray(array.toString());

					if (jsonArray2.length() == 0)
						return "1";
					// 如果取消了 则停止
					if (this.isCancelled()) {
						Log.i("x", "取消了异步。。。。");
						return null;
					}
					JSONObject items2 = array.getJSONObject(0);
					scheme.setId(items2.optString("id"));
					// 设置订单编号
					String schemeNum = items2.optString("SchemeNumber");
					// scheme.setSchemeNumber(schemeNum.equals("")
					// ? LotteryUtils.getSchemeNum(App.lottery.getLotteryID(),
					// App.lottery.getIsuseName(),
					// circleBean.topic.get(getInfoPosition).getSchemeid())
					// : schemeNum);
					scheme.setSchemeNumber(schemeNum);
					scheme.setIsHide(items2.optInt("isHide"));
					scheme.setSecretMsg(items2.optString("secretMsg"));
					scheme.setAssureMoney(items2.optDouble("assureMoney"));
					scheme.setAssureShare(items2.optInt("assureShare"));
					scheme.setBuyed(items2.optString("buyed"));
					scheme.setInitiateName(items2.optString("initiateName"));
					scheme.setInitiateUserID(items2.optString("initiateUserID"));
					String isPurchasing = items2.optString("isPurchasing");
					if ("".equals(isPurchasing)) {
						isPurchasing = isJoin + "";
					}
					scheme.setIsPurchasing(isPurchasing);

					// // 设置订单期号
					// scheme.setIsuseID(App.lottery.getIsuseId());
					// scheme.setIsuseName(App.lottery.getIsuseName());

					scheme.setLevel(items2.optInt("level"));
					scheme.setLotteryID(items2.optString("lotteryID"));
					scheme.setLotteryName(items2.optString("lotteryName"));
					scheme.setLotteryNumber(items2.optString("lotteryNumber"));
					scheme.setMoney(items2.optInt("money"));
					scheme.setPlayTypeID(items2.optInt("playTypeID"));
					scheme.setPlayTypeName(items2.optString("playTypeName"));
					scheme.setQuashStatus(items2.optInt("quashStatus"));
					scheme.setRecordCount(items2.optInt("recordCount"));
					scheme.setSchedule(items2.optInt("schedule"));
					scheme.setSchemeBonusScale(items2.optDouble("schemeBonusScale"));
					scheme.setSchemeIsOpened(items2.optString("schemeIsOpened"));
					scheme.setSecrecyLevel(items2.optInt("secrecyLevel"));
					scheme.setSerialNumber(items2.optInt("serialNumber"));
					scheme.setShare(items2.optInt("share"));
					scheme.setShareMoney(items2.optInt("shareMoney"));
					scheme.setSurplusShare(items2.optInt("surplusShare"));
					scheme.setTitle(items2.optString("title"));
					scheme.setWinMoneyNoWithTax(items2.optInt("winMoneyNoWithTax"));
					scheme.setWinNumber(items2.optString("winNumber"));

					// 设置订单下单时间
					scheme.setDateTime(LotteryUtils.getSchemeTime(System.currentTimeMillis()));

					scheme.setDescription(items2.optString("description"));
					scheme.setIsChase(items2.optInt("isChase"));
					scheme.setChaseTaskID(items2.optInt("chaseTaskID"));
					// 设置倍数
					// scheme.setMultiple(items2.optInt("Multiple"));
					scheme.setMultiple(20);
					scheme.setFromClient(items2.optInt("fromClient"));
					scheme.setMyBuyMoney(item.optInt("myBuyMoney") + "");
					scheme.setMyBuyShare(item.optInt("myBuyShare"));
					String schemeStatus = "待出票";
					try {
						schemeStatus = items2.getString("schemeStatus");
					} catch (JSONException e) {
						// do nothing
					}
					scheme.setSchemeStatus(schemeStatus);

					JSONArray array_contents = new JSONArray(items2.optString("buyContent"));
					List<LotteryContent> contents = new ArrayList<LotteryContent>();
					LotteryContent lotteryContent;
					for (int k = 0; k < array_contents.length(); k++) {
						lotteryContent = new LotteryContent();
						try {
							JSONArray array2 = new JSONArray(array_contents.optString(k));

							lotteryContent.setLotteryNumber(array2.getJSONObject(0).optString("lotteryNumber"));
							lotteryContent.setPlayType(array2.getJSONObject(0).optString("playType"));
							lotteryContent.setSumMoney(array2.getJSONObject(0).optString("sumMoney"));
							lotteryContent.setSumNum(array2.getJSONObject(0).optString("sumNum"));
							contents.add(lotteryContent);
						} catch (Exception e) {
							JSONObject array2 = new JSONObject(array_contents.optString(k));

							lotteryContent.setLotteryNumber(array2.optString("lotteryNumber"));
							lotteryContent.setPlayType(array2.optString("playType"));
							lotteryContent.setSumMoney(array2.optString("sumMoney"));
							lotteryContent.setSumNum(array2.optString("sumNum"));
							contents.add(lotteryContent);
						}
					}
					scheme.setBuyContent(contents);

					if (this.isCancelled()) {
						// pd.dismiss();
						Log.i("x", "取消了异步。。。。");
						return null;
					}
					return "0";
				}
			} catch (Exception e) {
				Log.i("x", "myAllLottery 错误" + e.getMessage());
			}

			return "-1";
		}

		@Override
		protected void onPostExecute(String result) {
			if (null == result)
				return;
			if ("1".equals(result)) {
				getMyHandler.sendEmptyMessage(-1);
			}
			getMyHandler.sendEmptyMessage(Integer.parseInt(result));
			super.onPostExecute(result);
		}
	}

	/**
	 * 进行页面刷新
	 */
	@SuppressLint("HandlerLeak")
	class getMyHandler extends Handler {
		
		
		@Override
		public void handleMessage(Message msg) {
			if (pd != null) {
				pd.dismiss();
			}
			try {
				ProgressDialogBar.stopProgress();
			} catch (Exception e) {
				// TODO: handle exception
			}
			switch (msg.what) {
			case 0:
				Log.e("x", scheme.getMultiple() + "");
				Intent intent_info;
				if ("72".equals(scheme.getLotteryID()) || "73".equals(scheme.getLotteryID())
						|| "45".equals(scheme.getLotteryID())) {

					intent_info = new Intent(CirclePersonInfo.this, MyCommonLotteryInfo_jc_other.class);
					App.scheme=scheme;
					intent_info.putExtra("scheme", scheme);
					intent_info.putExtra("id", id);
				} else {
					intent_info = new Intent(CirclePersonInfo.this, MyCommonLotteryInfo_other.class);
					intent_info.putExtra("scheme", scheme);
					App.scheme=scheme;
					intent_info.putExtra("id", id);
				}
				startActivity(intent_info);
				break;
			default:
				break;
			case -1:
				MyToast.getToast(CirclePersonInfo.this, "没有数据").show();
				break;
			case -500:
				MyToast.getToast(CirclePersonInfo.this, "连接超时").show();
				break;
			}
			super.handleMessage(msg);
		}
	}

}
